#!/bin/bash

echo "Extracting the data from the test speakers"
dataDir=speaker-adaptation/data
mkdir -p $dataDir
head -n 3 data/test/stm > data/test/comments.stm

for x in FDHC0 FELC0 FJLM0 FMGD0 FMLD0; do
  dir=$dataDir/$x
  mkdir -p $dir
  grep ^$x data/test/cmvn.scp > $dir/cmvn.scp
  grep ^$x data/test/feats.scp > $dir/feats.scp
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/spk2gender > $dir/spk2gender
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/utt2spk > $dir/utt2spk
  grep ^$x exp/dnn6_tri_fbank-dbn_dnn/decode_test/log/decode.1.log > $dir/text
  grep ^$x data/test/stm > $dir/temp.stm
  cat data/test/comments.stm $dir/temp.stm > $dir/stm
  rm $dir/temp.stm
  cp data/test/glm $dir
  utils/fix_data_dir.sh $dir 
done


for x in FNLP0 FPAS0 FPKT0 MBPM0 MCMJ0; do
  dir=$dataDir/$x
  mkdir -p $dir
  grep ^$x data/test/cmvn.scp > $dir/cmvn.scp
  grep ^$x data/test/feats.scp > $dir/feats.scp
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/spk2gender > $dir/spk2gender
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/utt2spk > $dir/utt2spk
  grep ^$x exp/dnn6_tri_fbank-dbn_dnn/decode_test/log/decode.2.log > $dir/text
  grep ^$x data/test/stm > $dir/temp.stm
  cat data/test/comments.stm $dir/temp.stm > $dir/stm
  rm $dir/temp.stm
  cp data/test/glm $dir
  utils/fix_data_dir.sh $dir
done


for x in MDAB0 MGRT0 MJDH0 MJLN0 MJMP0 ; do
  dir=$dataDir/$x
  mkdir -p $dir
  grep ^$x data/test/cmvn.scp > $dir/cmvn.scp
  grep ^$x data/test/feats.scp > $dir/feats.scp
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/spk2gender > $dir/spk2gender
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/utt2spk > $dir/utt2spk
  grep ^$x exp/dnn6_tri_fbank-dbn_dnn/decode_test/log/decode.3.log > $dir/text
  grep ^$x data/test/stm > $dir/temp.stm
  cat data/test/comments.stm $dir/temp.stm > $dir/stm
  rm $dir/temp.stm
  cp data/test/glm $dir
  utils/fix_data_dir.sh $dir
done


for x in MKLT0 MLLL0 MLNT0 MNJM0 MPAM0 ; do
  dir=$dataDir/$x
  mkdir -p $dir
  grep ^$x data/test/cmvn.scp > $dir/cmvn.scp
  grep ^$x data/test/feats.scp > $dir/feats.scp
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/spk2gender > $dir/spk2gender
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/utt2spk > $dir/utt2spk
  grep ^$x exp/dnn6_tri_fbank-dbn_dnn/decode_test/log/decode.4.log > $dir/text
  grep ^$x data/test/stm > $dir/temp.stm
  cat data/test/comments.stm $dir/temp.stm > $dir/stm
  rm $dir/temp.stm
  cp data/test/glm $dir
  utils/fix_data_dir.sh $dir
done


for x in MTAS1 MTLS0 MWBT0 MWEW0; do
  dir=$dataDir/$x
  mkdir -p $dir
  grep ^$x data/test/cmvn.scp > $dir/cmvn.scp
  grep ^$x data/test/feats.scp > $dir/feats.scp
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/spk2gender > $dir/spk2gender
  grep ^$x data/test/spk2utt > $dir/spk2utt
  grep ^$x data/test/utt2spk > $dir/utt2spk
  grep ^$x exp/dnn6_tri_fbank-dbn_dnn/decode_test/log/decode.5.log > $dir/text
  grep ^$x data/test/stm > $dir/temp.stm
  cat data/test/comments.stm $dir/temp.stm > $dir/stm
  rm $dir/temp.stm
  cp data/test/glm $dir
  utils/fix_data_dir.sh $dir
done

rm data/test/comments.stm
echo "Data extraction is complete"
